<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="vue.js"></script>
</head>

<body>
    <div id="app">
        <div class="imput-num">
            <button @click="sub"> - </button>
            <span>{{ num }}</span>
            <button @click="add"> + </button>
        </div>
    </div>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                num: 10
            },
            methods: {
                add: function () {
                    if (this.num < 20) {
                        this.num++;
                    } else {
                        alert("卖完了");
                    }
                },
                sub: function () {
                    if (this.num > 1) {
                        this.num--;
                    } else {
                        alert("过分了");
                    }
                }
            }
        })
    </script>
</body>

</html>